home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / perl5 / File::Find.z / File::Find
Encoding:
Text File  |  2002-10-03  |  3.4 KB  |  133 lines

  1.  
  2.  
  3.  
  4. FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))                                                    FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      find - traverse a file tree
  10.  
  11.      finddepth - traverse a directory structure depth-first
  12.  
  13. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  14.          use File::Find;
  15.          find(\&wanted, '/foo','/bar');
  16.          sub wanted { ... }
  17.  
  18.          use File::Find;
  19.          finddepth(\&wanted, '/foo','/bar');
  20.          sub wanted { ... }
  21.  
  22.  
  23. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  24.      The first argument to _f_i_n_d() is either a hash reference describing the
  25.      operations to be performed for each file, a code reference, or a string
  26.      that contains a subroutine name.  If it is a hash reference, then the
  27.      value for the key wanted should be a code reference.  This code reference
  28.      is called _t_h_e _w_a_n_t_e_d() _f_u_n_c_t_i_o_n below.
  29.  
  30.      Currently the only other supported key for the above hash is bydepth, in
  31.      presense of which the walk over directories is performed depth-first.
  32.      Entry point _f_i_n_d_d_e_p_t_h() is a shortcut for specifying { bydepth = 1}> in
  33.      the first argument of _f_i_n_d().
  34.  
  35.      The _w_a_n_t_e_d() function does whatever verifications you want.
  36.      $File::Find::dir contains the current directory name, and $_ the current
  37.      filename within that directory.  $File::Find::name contains
  38.      "$File::Find::dir/$_".  You are _c_h_d_i_r()'d to $File::Find::dir when the
  39.      function is called.  The function may set $File::Find::prune to prune the
  40.      tree.
  41.  
  42.      File::Find assumes that you don't alter the $_ variable.  If you do then
  43.      make sure you return it to its original value before exiting your
  44.      function.
  45.  
  46.      This library is useful for the find2perl tool, which when fed,
  47.  
  48.          find2perl / -name .nfs\* -mtime +7 \
  49.              -exec rm -f {} \; -o -fstype nfs -prune
  50.  
  51.      produces something like:
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))                                                    FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))
  71.  
  72.  
  73.  
  74.          sub wanted {
  75.              /^\.nfs.*$/ &&
  76.              (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
  77.              int(-M _) > 7 &&
  78.              unlink($_)
  79.              ||
  80.              ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
  81.              $dev < 0 &&
  82.              ($File::Find::prune = 1);
  83.          }
  84.  
  85.      Set the variable $File::Find::dont_use_nlink if you're using AFS, since
  86.      AFS cheats.
  87.  
  88.      finddepth is just like find, except that it does a depth-first search.
  89.  
  90.      Here's another interesting wanted function.  It will find all symlinks
  91.      that don't resolve:
  92.  
  93.          sub wanted {
  94.              -l && !-e && print "bogus link: $File::Find::name\n";
  95.          }
  96.  
  97.  
  98. BBBBUUUUGGGGSSSS
  99.      There is no way to make find or finddepth follow symlinks.
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.